home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 9
/
The PC-SIG Library on CD ROM - Ninth Edition.iso
/
401_500
/
DISK0417
/
DISK0417.ZIP
/
PROLOG.ARC
/
SAMPLES.ARC
/
APPENDS.PRO
< prev
next >
Wrap
Text File
|
1986-07-20
|
3KB
|
52 lines
/*
Note from Bob Morein: This file contributed by Steve Weaver
from Logicon, Inc., who created the art-deco comment style. The
"applist" predicate is available in type FS and above. However,
you can work with open lists without it. Suggested reference:
"Prolog for Programmers", by Kluzniak, Academic Press studies
in Data Processing #24, 1985, which is also the best logic
programming textbook I have seen, and much better than C & M.
The purpose of this file is to show how open lists can be appended
faster and more effectively than closed, "proper" lists, which are
the only types discussed in C & M. Examples of improper lists are
[a,b,c|3], or [a,b,c|X]. A list which terminates in a variable can
have another list appended to the tail without copying, which is
an inefficiency of the "append" predicate described in C & M.
*/
/****************************************************************************/
/***** Append two lists to create a third list *****/
/***** Converts input lists to open lists, does fast append, *****/
/***** then closes resulting list. *****/
/***** 1st arg is first list *****/
/***** 2nd arg is second list *****/
/***** 3rd arg is an openlist whose value is first appended to second ***/
/***** *****/
/***** NOTE: operator '--'MUST BE DECLARED: *****/
?-op(240,xfx,'--').
/****************************************************************************/
append(L1,L2,L3)
:- applist(L1,X,OL1),
applist(L2,Y,OL2),
d_conc(OL1--X,OL2--Y,L3--[]),
!.
append(L1,L2,L3)
:- apndslow(L1,L2,L3),
!.
apndslow([],L,L)
:- !.
apndslow([F|R],L2,[F|New_List])
:- apndslow(R,L2,New_List),
!.
/****************************************************************************/
/***** append two open lists to create a third open list *****/
/***** 1st arg is first openlist *****/
/***** 2nd arg is second openlist *****/
/***** 3rd arg is an openlist whose value is first appended to second ***/
/****************************************************************************/
d_conc(List1 -- Tail1,Tail1 -- Tail2,List1 -- Tail2).